package com.lesson3.singleton;

/**
 * @author 朝花不迟暮
 * @version 1.0
 * @date 2020/8/27 10:34
 * dcl
 */
public class LazyType2
{
    public static void main(String[] args)
    {
        Singleton4 instance = Singleton4.getInstance();
        Singleton4 instance1 = Singleton4.getInstance();
        System.out.println(instance.hashCode()==instance1.hashCode());
    }
}

class Singleton4
{
    private static volatile Singleton4 singleton4;

    private Singleton4()
    {

    }

    public static Singleton4 getInstance()
    {

        if (singleton4 == null)
        {
            synchronized (Singleton4.class)
            {
                if (singleton4 == null)
                {
                    singleton4 = new Singleton4();
                }
            }
        }
        return singleton4;
    }
}